<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>XHR 测试 Demo</title>
</head>
<body>
<button id="testBtn">发送请求</button>
<div id="result"></div>
<script>
  document.getElementById('testBtn').onclick = function() {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'http://localhost:8080/api/test', true);
    xhr.setRequestHeader('t-token', '23234');
    xhr.setRequestHeader('t123-token', '23234');
    xhr.onreadystatechange = function() {
      if (xhr.readyState === 4) {
        document.getElementById('result').textContent =
                xhr.status === 200 ? xhr.responseText : '请求失败: ' + xhr.status;
      }
    };
    xhr.send();
  };
</script>
</body>
</html>
